From e91295ab83f951f08e686ec6c18885f904de99a5 Mon Sep 17 00:00:00 2001 From: Aaron Schulz Date: Sun, 16 Mar 2008 18:46:09 +0000 Subject: [PATCH] rev_deleted merge: *Hide deleted content *Support rc_log_type/rc_log_action/ect... params *Use tables to avoid strange overflow --- includes/ChangesList.php | 295 +++++++++++++++++++++++++++++---------- 1 file changed, 220 insertions(+), 75 deletions(-) diff --git a/includes/ChangesList.php b/includes/ChangesList.php index 507e88fab5..d118df68f6 100644 --- a/includes/ChangesList.php +++ b/includes/ChangesList.php @@ -75,7 +75,7 @@ class ChangesList { : $nothing; $f .= $bot ? '' . $this->message['boteditletter'] . '' : $nothing; $f .= $patrolled ? '!' : $nothing; - return $f; + return "$f"; } /** @@ -101,6 +101,32 @@ class ChangesList { } } + /** + * int $field one of DELETED_* bitfield constants + * @return bool + */ + function isDeleted( $rc, $field ) { + return ($rc->mAttribs['rc_deleted'] & $field) == $field; + } + + /** + * Determine if the current user is allowed to view a particular + * field of this revision, if it's marked as deleted. + * @param int $field + * @return bool + */ + function userCan( $rc, $field ) { + if( ( $rc->mAttribs['rc_deleted'] & $field ) == $field ) { + global $wgUser; + $permission = ( $rc->mAttribs['rc_deleted'] & Revision::DELETED_RESTRICTED ) == Revision::DELETED_RESTRICTED + ? 'hiderevision' + : 'deleterevision'; + wfDebug( "Checking for $permission due to $field match on $rc->mAttribs['rc_deleted']\n" ); + return $wgUser->isAllowed( $permission ); + } else { + return true; + } + } function insertMove( &$s, $rc ) { # Diff @@ -136,10 +162,11 @@ class ChangesList { $s .= '(' . $this->skin->makeKnownLinkObj($title, $logname ) . ')'; } - function insertDiffHist(&$s, &$rc, $unpatrolled) { # Diff link - if( $rc->mAttribs['rc_type'] == RC_NEW || $rc->mAttribs['rc_type'] == RC_LOG ) { + if( !$this->userCan($rc,Revision::DELETED_TEXT) ) { + $diffLink = $this->message['diff']; + } else if( $rc->mAttribs['rc_type'] == RC_NEW || $rc->mAttribs['rc_type'] == RC_LOG ) { $diffLink = $this->message['diff']; } else { $rcidparam = $unpatrolled @@ -170,7 +197,12 @@ class ChangesList { $params = ( $unpatrolled && $rc->mAttribs['rc_type'] == RC_NEW ) ? 'rcid='.$rc->mAttribs['rc_id'] : ''; - $articlelink = ' '. $this->skin->makeKnownLinkObj( $rc->getTitle(), '', $params ); + if( $this->isDeleted($rc,Revision::DELETED_TEXT) ) { + $articlelink = $this->skin->makeKnownLinkObj( $rc->getTitle(), '', $params ); + $articlelink = ''.$articlelink.''; + } else { + $articlelink = ' '. $this->skin->makeKnownLinkObj( $rc->getTitle(), '', $params ); + } if( $watched ) $articlelink = "{$articlelink}"; global $wgContLang; @@ -190,15 +222,38 @@ class ChangesList { /** Insert links to user page, user talk page and eventually a blocking link */ function insertUserRelatedLinks(&$s, &$rc) { - $s .= $this->skin->userLink( $rc->mAttribs['rc_user'], $rc->mAttribs['rc_user_text'] ); - $s .= $this->skin->userToolLinks( $rc->mAttribs['rc_user'], $rc->mAttribs['rc_user_text'] ); + if ( $this->isDeleted($rc,Revision::DELETED_USER) ) { + $s .= ' ' . wfMsgHtml('rev-deleted-user') . ''; + } else { + $s .= $this->skin->userLink( $rc->mAttribs['rc_user'], $rc->mAttribs['rc_user_text'] ); + $s .= $this->skin->userToolLinks( $rc->mAttribs['rc_user'], $rc->mAttribs['rc_user_text'] ); + } + } + + /** insert a formatted action */ + function insertAction(&$s, &$rc) { + # Add action + if( $rc->mAttribs['rc_type'] == RC_LOG ) { + // log action + if ( $this->isDeleted($rc,LogPage::DELETED_ACTION) ) { + $s .= ' ' . wfMsgHtml('rev-deleted-event') . ''; + } else { + $s .= ' ' . LogPage::actionText( $rc->mAttribs['rc_log_type'], $rc->mAttribs['rc_log_action'], + $rc->getTitle(), $this->skin, LogPage::extractParams($rc->mAttribs['rc_params']), true, true ); + } + } } /** insert a formatted comment */ function insertComment(&$s, &$rc) { # Add comment if( $rc->mAttribs['rc_type'] != RC_MOVE && $rc->mAttribs['rc_type'] != RC_MOVE_OVER_REDIRECT ) { - $s .= $this->skin->commentBlock( $rc->mAttribs['rc_comment'], $rc->getTitle() ); + // log comment + if ( $this->isDeleted($rc,Revision::DELETED_COMMENT) ) { + $s .= ' ' . wfMsgHtml('rev-deleted-comment') . ''; + } else { + $s .= $this->skin->commentBlock( $rc->mAttribs['rc_comment'], $rc->getTitle() ); + } } } @@ -254,18 +309,22 @@ class OldChangesList extends ChangesList { $s .= '
  • '; - // moved pages + // Moved pages if( $rc_type == RC_MOVE || $rc_type == RC_MOVE_OVER_REDIRECT ) { $this->insertMove( $s, $rc ); - // log entries - } elseif ( $rc_namespace == NS_SPECIAL ) { + // Log entries + } elseif( $rc_log_type !='' ) { + $logtitle = Title::newFromText( "Log/$rc_log_type", NS_SPECIAL ); + $this->insertLog( $s, $logtitle, $rc_log_type ); + // Log entries (old format) or log targets, and special pages + } elseif( $rc_namespace == NS_SPECIAL ) { list( $specialName, $specialSubpage ) = SpecialPage::resolveAliasWithSubpage( $rc_title ); if ( $specialName == 'Log' ) { $this->insertLog( $s, $rc->getTitle(), $specialSubpage ); } else { wfDebug( "Unexpected special page in recentchanges\n" ); } - // all other stuff + // Log entries } else { wfProfileIn($fname.'-page'); @@ -287,9 +346,15 @@ class OldChangesList extends ChangesList { } $this->insertUserRelatedLinks($s,$rc); + $this->insertAction($s, $rc); $this->insertComment($s, $rc); - - $s .= rtrim(' ' . $this->numberofWatchingusers($rc->numberofWatchingusers)); + + # Mark revision as deleted + if ( !$rc_log_type && $this->isDeleted($rc,Revision::DELETED_TEXT) ) + $s .= ' ' . wfMsgHtml( 'deletedrev' ) . ''; + if($rc->numberofWatchingusers > 0) { + $s .= ' ' . wfMsg('number_of_watching_users_RCview', $wgContLang->formatNum($rc->numberofWatchingusers)); + } $s .= "
  • \n"; @@ -337,12 +402,14 @@ class EnhancedChangesList extends ChangesList { $rc->unpatrolled = false; } + $showdifflinks = true; # Make article link if( $rc_type == RC_MOVE || $rc_type == RC_MOVE_OVER_REDIRECT ) { $msg = ( $rc_type == RC_MOVE ) ? "1movedto2" : "1movedto2_redir"; $clink = wfMsg( $msg, $this->skin->makeKnownLinkObj( $rc->getTitle(), '', 'redirect=no' ), $this->skin->makeKnownLinkObj( $rc->getMovedToTitle(), '' ) ); } elseif( $rc_namespace == NS_SPECIAL ) { + // Log entries (old format) and special pages list( $specialName, $logtype ) = SpecialPage::resolveAliasWithSubpage( $rc_title ); if ( $specialName == 'Log' ) { # Log updates, etc @@ -352,7 +419,16 @@ class EnhancedChangesList extends ChangesList { wfDebug( "Unexpected special page in recentchanges\n" ); $clink = ''; } - } elseif( $rc->unpatrolled && $rc_type == RC_NEW ) { + } elseif( $rc_log_type !='' ) { + // Log entries + $logtitle = Title::newFromText( "Log/$rc_log_type", NS_SPECIAL ); + $logname = LogPage::logName( $rc_log_type ); + $clink = '(' . $this->skin->makeKnownLinkObj($logtitle, $logname ) . ')'; + } if( $this->isDeleted($rc,Revision::DELETED_TEXT) ) { + $clink = '' . $this->skin->makeKnownLinkObj( $rc->getTitle(), '' ) . ''; + if ( !ChangesList::userCan($rc,Revision::DELETED_TEXT) ) + $showdifflinks = false; + } else if( $rc->unpatrolled && $rc_type == RC_NEW ) { # Unpatrolled new page, give rc_id in query $clink = $this->skin->makeKnownLinkObj( $rc->getTitle(), '', "rcid={$rc_id}" ); } else { @@ -375,7 +451,12 @@ class EnhancedChangesList extends ChangesList { $querydiff = $curIdEq."&diff=$rc_this_oldid&oldid=$rc_last_oldid$rcIdQuery"; $aprops = ' tabindex="'.$baseRC->counter.'"'; $curLink = $this->skin->makeKnownLinkObj( $rc->getTitle(), $this->message['cur'], $querycur, '' ,'', $aprops ); - if( $rc_type == RC_NEW || $rc_type == RC_LOG || $rc_type == RC_MOVE || $rc_type == RC_MOVE_OVER_REDIRECT ) { + + # Make "diff" an "cur" links + if ( !$showdifflinks ) { + $curLink = $this->message['cur']; + $diffLink = $this->message['diff']; + } else if( $rc_type == RC_NEW || $rc_type == RC_LOG || $rc_type == RC_MOVE || $rc_type == RC_MOVE_OVER_REDIRECT ) { if( $rc_type != RC_NEW ) { $curLink = $this->message['cur']; } @@ -383,23 +464,29 @@ class EnhancedChangesList extends ChangesList { } else { $diffLink = $this->skin->makeKnownLinkObj( $rc->getTitle(), $this->message['diff'], $querydiff, '' ,'', $aprops ); } - + # Make "last" link - if( $rc_last_oldid == 0 || $rc_type == RC_LOG || $rc_type == RC_MOVE || $rc_type == RC_MOVE_OVER_REDIRECT ) { + if( !$showdifflinks ) { + $lastLink = $this->message['last']; + } else if( $rc_last_oldid == 0 || $rc_type == RC_LOG || $rc_type == RC_MOVE || $rc_type == RC_MOVE_OVER_REDIRECT ) { $lastLink = $this->message['last']; } else { $lastLink = $this->skin->makeKnownLinkObj( $rc->getTitle(), $this->message['last'], - $curIdEq.'&diff='.$rc_this_oldid.'&oldid='.$rc_last_oldid . $rcIdQuery ); + $curIdEq.'&diff='.$rc_this_oldid.'&oldid='.$rc_last_oldid . $rcIdQuery ); + } + + # Make user links + if ( $this->isDeleted($rc,Revision::DELETED_USER) ) { + $rc->userlink = ' ' . wfMsgHtml('rev-deleted-user') . ''; + } else { + $rc->userlink = $this->skin->userLink( $rc_user, $rc_user_text ); + $rc->usertalklink = $this->skin->userToolLinks( $rc_user, $rc_user_text ); } - - $rc->userlink = $this->skin->userLink( $rc_user, $rc_user_text ); $rc->lastlink = $lastLink; $rc->curlink = $curLink; $rc->difflink = $diffLink; - $rc->usertalklink = $this->skin->userToolLinks( $rc_user, $rc_user_text ); - # Put accumulated information into the cache, for later display # Page moves go on their own line $title = $rc->getTitle(); @@ -421,10 +508,11 @@ class EnhancedChangesList extends ChangesList { */ function recentChangesBlockGroup( $block ) { global $wgLang, $wgContLang, $wgRCShowChangedSize; - $r = ''; + $r = ''; # Collate list of users $isnew = false; + $namehidden = true; $unpatrolled = false; $userlinks = array(); foreach( $block as $rcObj ) { @@ -432,6 +520,11 @@ class EnhancedChangesList extends ChangesList { if( $rcObj->mAttribs['rc_new'] ) { $isnew = true; } + // If all log actions to this page were hidden, then don't + // give the name of the affected page for this block! + if( !($rcObj->mAttribs['rc_deleted'] & LogPage::DELETED_ACTION) ) { + $namehidden = false; + } $u = $rcObj->userlink; if( !isset( $userlinks[$u] ) ) { $userlinks[$u] = 0; @@ -465,24 +558,25 @@ class EnhancedChangesList extends ChangesList { $toggleLink = "javascript:toggleVisibility('$rci','$rcm','$rcl')"; $tl = '' . $this->sideArrow() . ''; $tl .= ''; - $r .= $tl; + $r .= '
    '.$tl; # Main line - $r .= ''; - $r .= $this->recentChangesFlags( $isnew, false, $unpatrolled, ' ', $bot ); + $r .= ' '.$this->recentChangesFlags( $isnew, false, $unpatrolled, ' ', $bot ); # Timestamp - $r .= ' '.$block[0]->timestamp.' '; + $r .= ' '.$block[0]->timestamp.' '; # Article link - $r .= $this->maybeWatchedLink( $block[0]->link, $block[0]->watched ); + if ( $namehidden ) + $r .= ' ' . wfMsgHtml('rev-deleted-event') . ''; + else + $r .= $this->maybeWatchedLink( $block[0]->link, $block[0]->watched ); $r .= $wgContLang->getDirMark(); $curIdEq = 'curid=' . $block[0]->mAttribs['rc_cur_id']; $currentRevision = $block[0]->mAttribs['rc_this_oldid']; if( $block[0]->mAttribs['rc_type'] != RC_LOG ) { # Changes - $n = count($block); static $nchanges = array(); if ( !isset( $nchanges[$n] ) ) { @@ -492,25 +586,25 @@ class EnhancedChangesList extends ChangesList { $r .= ' ('; - if( $isnew ) { + if( !ChangesList::userCan($rcObj,Revision::DELETED_TEXT) ) { + $r .= $nchanges[$n]; + } else if( $isnew ) { $r .= $nchanges[$n]; } else { $r .= $this->skin->makeKnownLinkObj( $block[0]->getTitle(), $nchanges[$n], $curIdEq."&diff=$currentRevision&oldid=$oldid" ); } - $r .= ') . . '; - if( $wgRCShowChangedSize ) { # Character difference $chardiff = $rcObj->getCharacterDifference( $block[ count( $block ) - 1 ]->mAttribs['rc_old_len'], $block[0]->mAttribs['rc_new_len'] ); if( $chardiff == '' ) { - $r .= ' ('; + $r .= ') '; } else { $r .= ' ' . $chardiff. ' . . '; } - } + } # History $r .= '(' . $this->skin->makeKnownLinkObj( $block[0]->getTitle(), @@ -519,51 +613,70 @@ class EnhancedChangesList extends ChangesList { } $r .= $users; - - $r .= $this->numberofWatchingusers($block[0]->numberofWatchingusers); - $r .= "
    \n"; + $r .=$this->numberofWatchingusers($block[0]->numberofWatchingusers); + + $r .= "
    \n"; # Sub-entries - $r .= '